<template>
    <h1>添加用户</h1>
    <table class="table table-bordered">
        <tr>
            <td>用户名</td>
            <td><input type="text" v-model="info.Uname"></td>
        </tr>
        <tr>
            <td>密码</td>
            <td><input type="text" v-model="info.Upwd"></td>
        </tr>
        <tr>
            <td colspan="2"><input type="button" value="添加" @click="AddUser"></td>
        </tr>

    </table>
</template>
<script setup lang="ts">
import { ref,onMounted } from 'vue';
import { useRouter, useRoute} from 'vue-router';
import axios from 'axios';
import { useStore } from '../../store/index.ts';


const store = useStore();
const router = useRouter();
const route = useRoute();

const info = ref({
    Uname: '',
    Upwd: '',
   
});

// const type = ref({
//     Tid:0,
//     Tname:'',
// })

// onMounted(() => {
//     bind();
// })


// const bind = () => {
//     // console.log(info.value);
//     axios({
//         method: 'get',
//         url: 'http://localhost:61498/api/UserInAll/BindType',
//     })
//     .then((res) => {
//         console.log(res.data);
//         type.value = res.data;
//         // console.log(type.value);
//     })
//     .catch((err) => {
//         console.log(err);
        
//     })
   
// };

const AddUser = () => {
    if(info.value.Uname==''){
        alert('用户名不能为空');
        return;
    }
    
    if(info.value.Upwd==''){
        alert('密码不能为空');
        return;
    }
        axios({
            method: 'post',
            url: 'http://localhost:61498/api/UserInAll/AddUser',
            data: info.value,
        })
        .then((res) => {
            console.log(res.data);
            if(res.data>0){
                alert('添加成功');
                router.push('/SelUser');
            }
            else if(res.data==-1){
                alert('名称不能重复');
                
            }
            else
            {
                alert('添加失败');
            }
            
        })
        .catch((err) => {
            console.log(err);
            
        })
    
};
</script>